<template>
  <div class="zh-tabbar">
    <div class="zh-tabbar-inner">
      <div class="tabbar-box" v-for="item in tabIcon" :key="item.key" :class="{ 'is-active': item.key === pathName }" @click="routerEnter(item)">
        <i :class="['iconfont', item.icon ]"></i>
        <div class="text">{{ item.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tabIcon: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      pathName: ''
    }
  },
  watch: {
    $route: 'routerChange'
  },
  methods: {
    routerEnter (item) {
      if (this.$route.name === item.key) return false
      this.$router.push({ name: item.key })
      this.$emit('taggerNavBar', item)
    },
    routerChange (to, from) {
      this.pathName = to.name
    }
  }
}
</script>

<style lang="less" scoped>
  .zh-tabbar {
    background: #fff;
    width: 100%;
    position: fixed;
    bottom: 0px;
    z-index: 99;
    border-top: 1px solid #eee;
    text-align: center;
    padding-bottom: 10px;
    .zh-tabbar-inner {
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      .tabbar-box {
        width: 100%;
        .text {
          font-size: 12px;
          margin-top: 2px;
        }
      }
      .is-active {
        color: #f4c900;
      }
    }
  }
</style>
